<?php
/**
 * get the all the city name for a trail
 * 
 * @package   App_Sample
 * @author    Chen Qiao <chen.qiao@evebit.com>
 * @version   $$Id: GetTrailCityName.php 1464 2011-06-29 06:36:32Z chen.qiao $$
 */
class Evebit_View_Helper_GetTrailCityName extends Zend_View_Helper_Abstract {
	
	/**
	 * get the all city name with the trailId
	 * @param int $trailId
	 * @return string
	 */
	public function getTrailCityName($trailId) {
		$planner = new Planner_Model_Entity_Planner();
		$collection = $planner->getCollection();
		$collection->addFieldToFilter('travel_id',$trailId);
		$data = $collection->getData();
		$infoArr = array();
		$cityNameArr = array();	
		$cityNameHtml = '';	
		foreach($data as $value) {
			$flag = true;
			$infoId = $value['info_id'];
			$cityName = $this->getCityName($infoId);
			if($cityNameArr) {
				foreach($cityNameArr as $info) {
					if($info == $cityName) {
						$flag = false;
						break;
					}
				}
			}
			if($flag) {
				$cityNameArr[] = $cityName;
			}
		}
		foreach($cityNameArr as $city) {
			$cityNameHtml = $cityNameHtml.$city.'<br/>';
		}
		return $cityNameHtml;
	}
	
	/**
	 * get the city name with the infoId
	 * @param int $infoId
	 * @return string
	 */
	public function getCityName($infoId) {
		$cityName = '';
		$infoEntity = new Information_Model_Entity_Information();
		$id = $infoEntity->getResource()->infoIdToId($infoId);
    	$infoData = $infoEntity->load($id);
    	$type = $infoData->getType();
    	if($type == 'city') {
    		$cityName = $infoData->getName();
    	} else {
    		$city = $infoData->getCity();
    		$cityName = $city['name'];
    	}
    	return $cityName;
	}
	
}